var box_choose = (function():Object{

    // 显示的盒子样式
    const box_attr = {
        style:"border:1px dashed #ff0000"
    };

    // 是否已经开始绘制
    let isStart:Boolean = false;

    // 起始点
    let startPoint = {
        x:0,
        y:0
    };

    // 末尾点
    let endPoint = {
        x:0,
        y:0
    };

    let box:HTMLElement = document.createElement("div");

    box.style.cssText = box_attr.style;

    box.style.position = "absolute";

    function start(x:number,y:number):void{
        startPoint.x = x;
        startPoint.y = y;
        box.style.left = x + "px";
        box.style.top = y + "px";
        box.style.width = 0 + "px";
        box.style.height = 0 + "px";
        if(!isStart){
            document.body.appendChild(box);
        }
        isStart = true;
    }

    function move(x:number,y:number):void{
        endPoint.x = x;
        endPoint.y = y;
        
        if(startPoint.x > endPoint.x){
            box.style.left = endPoint.x + "px";
        }
        if(startPoint.y > endPoint.y){
            box.style.top = endPoint.y + "px";
        }
        
        box.style.height = Math.abs(y - startPoint.y) + "px";
        box.style.width = Math.abs(x - startPoint.x) + "px";
    }

    function end():void{
        box.style.left = 0 + "px";
        box.style.top = 0 + "px";
        box.style.width = 0 + "px";
        box.style.height = 0 + "px";
        // 起始点
        startPoint = {
            x:0,
            y:0
        };

        // 末尾点
        endPoint = {
            x:0,
            y:0
        };

        isStart = false;

        document.body.removeChild(box);
    }

    return {
        start,
        move,
        end
    }
}())